package ru.ifmo.trafficspy;

import java.io.PrintWriter;
import java.util.List;
import java.util.Random;

import ru.ifmo.trafficspy.analyzer.TrafficModel;
import ru.ifmo.trafficspy.analyzer.learning.TrafficModelFactory;
import ru.ifmo.trafficspy.common.Item;
import ru.ifmo.trafficspy.provider.FirstProvider;
import ru.ifmo.trafficspy.provider.Provider;
import ru.ifmo.trafficspy.provider.SecondProvider;

public class Tester {
	
	private void test() {
		FirstProvider fp = new FirstProvider(100);
		SecondProvider sp = new SecondProvider(100);
		TrafficModel tm1 = TrafficModelFactory.getTrafficModel(fp.getTraffic(), 1, 1, 2, "", 500);
		TrafficModel tm2 = TrafficModelFactory.getTrafficModel(sp.getTraffic(), 2, 1, 2, "", 1000);

		Random random = new Random();
		PrintWriter out = new PrintWriter(System.out);
		int n = 1000;
		for (int len = 1; len <= 300; len++) {
			Provider[] p = new Provider[2];
			p[0] = new FirstProvider(len);
			p[1] = new SecondProvider(len);
			int correct = 0;
			for (int i = 0; i < n; i++) {
				int type = random.nextInt(2);
				List<Item> traffic = p[type].getTraffic();
				int guess = -1;
				if (tm1.getProbability(traffic) > tm2.getProbability(traffic)) {
					guess = 0;
				} else {
					guess = 1;
				}
				if (guess == type) {
					correct++;
				}
			}
			System.out.println(len + " " + correct * 1.0 / n);
			System.out.flush();
 		}
		tm1.write(out);
		tm2.write(out);
		out.close();
	}
	
	public static void main(String[] args) {
		new Tester().test();
	}
}
